package com.cheetah.start.common.listener;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.*;

/**
 * session 侦听器
 *
 * @author Feel
 * @date 2021/08/10
 */
@Slf4j
@WebListener
public class OnLineListener implements HttpSessionListener, HttpSessionAttributeListener {

    @Override
    public void sessionCreated(HttpSessionEvent event) {
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent event) {
        HttpSession se = event.getSession();
        //从列表中删除
        OnLineManager.getInstance().removeSession(se);

    }

    @Override
    public void attributeAdded(HttpSessionBindingEvent event) {
        HttpSession se = event.getSession();
        //添加
        OnLineManager.getInstance().addSession(se);
    }


}
